<script setup>
import { computed, ref } from 'vue'

// 在 script 中使用ref声明的变量, 需要使用.value来获取
// 在 template 中使用ref声明的变量, 不需要使用.value来获取
// 底层就是使用reactive实现的, 所以需要使用.value来获取
const count = ref({
  count: 0,
})
const addCount = () => {
  count.value.count++
}

const result = computed(() => {
  return count.value.count * 2
})
</script>
<template>
  <div class="box">
    <button class="my-button" @click="addCount">
      result {{ count.count }}
    </button>
    <div>
      <p>new Result{{ result }}</p>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.box {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  padding: 20px;
}

.my-button {
  display: inline-block;
  text-align: center;
  vertical-align: middle;
  padding: 15px 32px;
  text-decoration: none;
  font-size: 16px;
  font-weight: 500;
  border-radius: 4px;
  border: none;
  cursor: pointer;

  background-color: #4caf50;
  color: white;

  transition: background-color 0.3s ease;
  &:hover {
    background-color: #45a049;
  }

  &:active {
    background-color: #388e3c;
  }
}
</style>
